
package orca;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public abstract class OrcaComponent
{
	final Rectangle frame;
	
	private Color background = null;
	private Color foreground = null;
	private int maxSize;
	
	public String name = null;

	OrcaComponent brother = null;

	public OrcaComponent()
	{
		this.frame = new Rectangle();
		this.maxSize = Integer.MAX_VALUE;
		
		this.setForeground(OrcaContext.FOREGROUND);
		this.setBackground(OrcaContext.BACKGROUND);
	}
	
	public boolean setMaxSize(int maxSize)
	{
		// TODO implementer la validation
		boolean ok = true;
		if (ok)
		{
			this.maxSize = maxSize;
		}
		
		return ok;
	}
	
	public int getMaxSize()
	{
		return this.maxSize;
	}
	
	public boolean setForeground(Color foreground)
	{
		// TODO implementer la validation
		boolean ok = true;
		if (ok)
		{
			this.foreground = foreground;
		}
		
		return ok;
	}
	
	public Color getForeground()
	{
		return this.foreground;
	}
	
	public boolean setBackground(Color background)
	{
		// TODO implementer la validation
		boolean ok = true;
		if (ok)
		{
			this.background = background;
		}
		
		return ok;
	}
	
	public Color getBackground()
	{
		return this.background;
	}

	public int getNbBrothers()
	{
		if (this.brother != null)
		{
			return 1 + this.brother.getNbBrothers();
		}
		else
		{
			return 1;
		}
	}

	@Override
	public String toString()
	{
		return this.name;
	}

	void setFrame(Rectangle rect)
	{
		this.frame.setBounds(rect);
	}

	abstract void setBounds(int x, int y, int width, int height);

	abstract void refresh(Graphics2D g2d);

	public abstract void mouseClicked(int button, int x, int y);

	public abstract void mousePressed(int button, int x, int y);

	public abstract void mouseReleased(int button, int x, int y);
}
